<%-- 
    Document   : comment
    Created on : Nov 22, 2012, 5:27:17 PM
    Author     : Psy Fox
--%>

<%@page import="tracker.Comments"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Collection"%>
<%@page import="tracker.Users"%>
<%@page import="tracker.TrackerHelper"%>
<%@page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/jquery.validate.pack.js"></script>
<script type="text/javascript">
    $(function() {
		
        $(".submit").click(function() {
            var userid = $("#userid").val();	
            var torrentid = $("#torrentid").val();
            var comment = $("#comment").val();
            var dataString = 'comment=' + comment +'&userid=' + userid + '&torrentid=' + torrentid;
		
            if(comment=='')
            {
                alert('Please fill in name and comment textbox');
            } else {
                $("#flash").show();
                $("#flash").fadeIn(400).html('<img src="style/img/ajax-loader.gif" align="absmiddle">&nbsp;<span class="loading">Loading Comment...</span>');
                $.ajax({
                    type: "POST",
                    url: "cmteditor.jsp",
                    data: dataString,
                    cache: false,
                    success: function(html){	 
                        $("ul#update").append(html);
                        $("ul#update li:last").fadeIn("slow");
                        $("#comment").val('');	 
                        $("#flash").hide();
                    }
                });		
                return false;
            }
        });
    });
</script>
<div id="main">
    <ul  id="update" class="timeline">
        <%
            try {
                TrackerHelper helper = new TrackerHelper();
                Collection<Comments> list = helper.getComments();
                Iterator<Comments> it = list.iterator();
                while (it.hasNext()) {
                    Comments comment = it.next();
                    if (comment.getTorrents().getTorrentId() == Integer.valueOf(request.getParameter("torrentid"))) {


        %>
        <li class="box">
            <a href="singleUser.jsp?userId=<%= comment.getUsers().getUserId()%>"><h4><%= comment.getUsers().getUserName()%></h4></a>
            <p><%= comment.getCommentContent()%></p>
        </li>
        <% }
                }
            } catch (Exception e) {
                System.out.println("Error in ListUsersTag: " + e.getMessage());
            }
        %>

        <%
            int torrentId = Integer.valueOf(request.getParameter("torrentid"));
            int userId = Integer.valueOf(request.getParameter("userid"));
        %>
    </ul>
    <div id="flash" align="left"  ></div>
    <div style="margin-left:100px">
        <form action="" method="post">
            <br />
            <label>
                <input type="hidden" id="userid" name="name1" value="<%= userId%>">
                <input type="hidden" id="torrentid" name="name2" value="<%= torrentId%>">
                <input type="hidden" id="commenth" name="name2" value="">
                <textarea name="comment" id="comment"></textarea>
                <span class="titles">Comment<span class="star">*</span></span>
            </label>
            <br />
            <input type="submit" class="submit" value=" Send Comment " />
        </form>
    </div>
</div>